﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using System.IO;
using Facebook_Graph_Toolkit;
using Facebook_Graph_Toolkit.GraphApi;

public partial class _Default : System.Web.UI.Page
{
    string postedBy, watchman, parameters, Pets, secSubCat, subcategorey, facebookId;
    int minPrice, maxPrice, minSqfts, maxSqfts, BR, BA, CarParking, ascOrder, clientId, active;
    bool flag = true, post = false;

    protected void Page_Load(object sender, EventArgs e)
    {

        this.ClientScript.GetPostBackEventReference(this, "arg");

        if (!IsPostBack)
        {
            if ((Request.QueryString["ClientId"] != null) && (Request.QueryString["Active"] != null))
            {
                setHiddenVariables();
                loadAllListingInformationOfParticularAgent();
            }
            else
            {
                setHiddenVariables();
                loadAllListingInformation();
            }

            if (Request.QueryString["Posted"] != null)
            {
                if (Request.QueryString["Posted"].ToString() == "ME")
                {
                    postedByMe();
                }

                if (Request.QueryString["Posted"].ToString() == "MYFriends")
                {
                    postedByMyFriends();
                }
            }
            else
            {
                Session["Facebook"] = null;
            }
        }
        else
        {
            Control c = GetPostBackControl(this.Page);

            if (Request.QueryString["Navigation"] == "ViewRentals")// && ((System.Web.UI.WebControls.LinkButton)(c)).Text == "View Rentals")
            {
                if (Session["Navigation"] != null)
                {
                    secSubCatPanel.Visible = false;
                    imgBanglowTick.Visible = false;
                    imgAllTick.Visible = true;
                    imgCommercialTick.Visible = false;
                    imgApartmentTick.Visible = false;
                    imgIndividualTick.Visible = false;
                    lblSelectedSubCategorey.Text = "All";
                    lblSelectedSubCategorey.Visible = false;

                    Session["subcategorey"] = "0";

                    PostedByUndo();
                    PriceUndo();
                    BRUndo();
                    BAUndo();
                    PetsUndo();
                    SqftsUndo();
                    CarUndo();
                    WatchmanUndo();
                    ParametersUndo();

                    txtLow.Text = "";
                    txtHigh.Text = "";

                    secSubCatPanel.Visible = false;

                    txtMin.Text = "";
                    txtMax.Text = "";

                    loadAllListingInformation();
                    Session["Navigation"] = null;
                }
            }

        }


        string eventTarget = this.Request["__EVENTTARGET"];
        string eventArgument = this.Request["__EVENTARGUMENT"];

        if (eventTarget != String.Empty && eventTarget == "callPostBack" && eventArgument == "btnSearchClick")
        {
            SearchWithPrice();
        }

        if (eventTarget != String.Empty && eventTarget == "callPostBack" && eventArgument == "btnSqftsClick")
        {
            SearchWithSqfts();
        }
    }

    private void SearchWithPrice()
    {
        linkPriceUndo.Visible = true;

        Session["minPrice"] = txtLow.Text;
        Session["maxPrice"] = txtHigh.Text;

        loadAllListingInformation();
    }

    private void SearchWithSqfts()
    {
        linkSqftsUndo.Visible = true;

        Session["minSqfts"] = txtMin.Text;
        Session["maxSqfts"] = txtMax.Text;

        loadAllListingInformation();
    }

    public static Control GetPostBackControl(System.Web.UI.Page page)
    {
        Control control = null;

        string ctrlname = page.Request.Params.Get("__EVENTTARGET");
        if (ctrlname != null && ctrlname != string.Empty)
        {
            control = page.FindControl(ctrlname);
        }
        else
        {
            foreach (string ctl in page.Request.Form)
            {
                Control c = page.FindControl(ctl);
                if (c is System.Web.UI.WebControls.Button)
                {
                    control = c;
                    break;
                }
            }
        }
        return control;
    }

    private void GetfacebookId()
    {
        if (Request["code"] != null)
        {
            postedByMe();
        }
    }

    private void loadAllListingInformationOfParticularAgent()
    {
        Session["clientId"] = Request.QueryString["ClientId"];
        Session["active"] = Request.QueryString["Active"];

        getHiddenVariables();
        DataSet dsRental = new DataSet();
        dsRental = BuddyAgentDAL.searchPatternRental(postedBy, subcategorey, secSubCat, minPrice, maxPrice, BR, BA, CarParking, minSqfts, maxSqfts,
            watchman, parameters, Pets, ascOrder, clientId, facebookId, active);

        //ControlPlace.Controls.Clear();
        NoListingAvailable.Visible = false;
        if (dsRental.Tables[0].Rows.Count == 0)
        {
            gvControls.DataSource = null;
            gvControls.DataBind();

            NoListingInfoAvailable();
            flag = false;
        }
        else
        {
            flag = true;
            int firstValue, lastValue;

            //firstValue = (gvControls.PageIndex) * (gvControls.PageSize) + 1;
            firstValue = 1;
            //lastValue = (gvControls.PageIndex + 1) * (gvControls.PageSize);
            lastValue = gvControls.PageSize;

            if (lastValue > dsRental.Tables[0].Rows.Count)
                lastValue = dsRental.Tables[0].Rows.Count;

            lblRentalCount.Text = "Rentals ( " + firstValue.ToString() + " - " + lastValue.ToString() + " of " + dsRental.Tables[0].Rows.Count.ToString() + " )";


            gvControls.DataSource = dsRental.Tables[0];
            gvControls.DataBind();
        }
        if (!IsPostBack)
            setAllCounts(dsRental);
        else
            setCounts(dsRental);
        if (post)
        {
            setAllCounts(dsRental);
            post = false;
        }

    }

    private void setHiddenVariables()
    {
        facebookId = "0";
        postedBy = "0";
        subcategorey = "0";
        minPrice = -1;
        maxPrice = -1;
        BR = -1;
        BA = -1;
        CarParking = -1;
        minSqfts = -1;
        maxSqfts = -1;
        watchman = "0";
        parameters = "0";
        Pets = "0";
        secSubCat = "0";
        ascOrder = -1;
        clientId = -1;
        active = -1;

        Session["facebookId"] = facebookId;
        Session["clientId"] = clientId;
        Session["active"] = active;
        Session["ascOrder"] = ascOrder;
        Session["postedBy"] = postedBy;
        Session["subcategorey"] = subcategorey;
        Session["minPrice"] = minPrice;
        Session["maxPrice"] = maxPrice;
        Session["BR"] = BR;
        Session["BA"] = BA;
        Session["CarParking"] = CarParking;
        Session["minSqfts"] = minSqfts;
        Session["maxSqfts"] = maxSqfts;
        Session["watchman"] = watchman;
        Session["parameters"] = parameters;
        Session["Pets"] = Pets;
        Session["secSubCat"] = secSubCat;
    }

    private void setHiddenVariablesWithOutPosted()
    {
        subcategorey = "0";
        minPrice = -1;
        maxPrice = -1;
        BR = -1;
        BA = -1;
        CarParking = -1;
        minSqfts = -1;
        maxSqfts = -1;
        watchman = "0";
        parameters = "0";
        Pets = "0";
        secSubCat = "0";
        ascOrder = -1;
        clientId = -1;
        active = -1;


        Session["clientId"] = clientId;
        Session["active"] = active;
        Session["ascOrder"] = ascOrder;
        Session["subcategorey"] = subcategorey;
        Session["minPrice"] = minPrice;
        Session["maxPrice"] = maxPrice;
        Session["BR"] = BR;
        Session["BA"] = BA;
        Session["CarParking"] = CarParking;
        Session["minSqfts"] = minSqfts;
        Session["maxSqfts"] = maxSqfts;
        Session["watchman"] = watchman;
        Session["parameters"] = parameters;
        Session["Pets"] = Pets;
        Session["secSubCat"] = secSubCat;
    }

    private void getHiddenVariables()
    {
        ascOrder = Convert.ToInt32(Session["ascOrder"]);
        facebookId = Session["facebookId"].ToString();
        clientId = Convert.ToInt32(Session["clientId"]);
        active = Convert.ToInt32(Session["active"]);
        postedBy = Session["postedBy"].ToString();
        subcategorey = Session["subcategorey"].ToString();
        minPrice = Convert.ToInt32(Session["minPrice"]);
        maxPrice = Convert.ToInt32(Session["maxPrice"]);
        BR = Convert.ToInt32(Session["BR"].ToString());
        BA = Convert.ToInt32(Session["BA"].ToString());
        CarParking = Convert.ToInt32(Session["CarParking"].ToString());
        minSqfts = Convert.ToInt32(Session["minSqfts"]);
        maxSqfts = Convert.ToInt32(Session["maxSqfts"]);
        watchman = Session["watchman"].ToString();
        parameters = Session["parameters"].ToString();
        Pets = Session["Pets"].ToString();
        secSubCat = Session["secSubCat"].ToString();
    }

    private void loadAllListingInformation()
    {
        getHiddenVariables();
        DataSet dsRental = new DataSet();
        dsRental = BuddyAgentDAL.searchPatternRental(postedBy, subcategorey, secSubCat, minPrice, maxPrice, BR, BA, CarParking, minSqfts, maxSqfts,
            watchman, parameters, Pets, ascOrder, clientId, facebookId, active);

        //ControlPlace.Controls.Clear();
        NoListingAvailable.Visible = false;
        if (dsRental.Tables[0].Rows.Count == 0)
        {
            gvControls.DataSource = null;
            gvControls.DataBind();

            NoListingInfoAvailable();
            flag = false;
        }
        else
        {
            flag = true;
            int firstValue, lastValue;

            //firstValue = (gvControls.PageIndex) * (gvControls.PageSize) + 1;
            firstValue = 1;
            //lastValue = (gvControls.PageIndex + 1) * (gvControls.PageSize);
            lastValue = gvControls.PageSize;

            if (lastValue > dsRental.Tables[0].Rows.Count)
                lastValue = dsRental.Tables[0].Rows.Count;

            lblRentalCount.Text = "Rentals ( " + firstValue.ToString() + " - " + lastValue.ToString() + " of " + dsRental.Tables[0].Rows.Count.ToString() + " )";


            gvControls.DataSource = dsRental.Tables[0];
            gvControls.DataBind();
        }
        if (!IsPostBack)
            setAllCounts(dsRental);
        else
            setCounts(dsRental);
        if (post)
        {
            setAllCounts(dsRental);
            post = false;
        }

        //PagedDataSource page = new PagedDataSource();
        //page.AllowCustomPaging = true;
        //page.AllowPaging = true;
        //page.DataSource = dtListingInformation.DefaultView;
        //page.PageSize = 10;
        //Repeater1.DataSource = page;
        //Repeater1.DataBind();
    }

    private void setCounts(DataSet dsRental)
    {
        lblPostedByMeCount.Text = "(" + dsRental.Tables[1].Rows[0]["PostedByMe"].ToString() + ")";
        lblPostedByFriendsCount.Text = "(" + dsRental.Tables[1].Rows[0]["PostedByFriends"].ToString() + ")";
        lblPostedByAllCount.Text = "(" + dsRental.Tables[1].Rows[0]["PostedByAll"].ToString() + ")";


        //lblAllCount.Text = "(" + dsRental.Tables[1].Rows[0]["SubCategoreyAll"].ToString() + ")";
        //lblCommercialCount.Text = "(" + dsRental.Tables[1].Rows[0]["Commercial"].ToString() + ")";
        //lblApartmentCount.Text = "(" + dsRental.Tables[1].Rows[0]["Apartment"].ToString() + ")";
        //lblIndividualCount.Text = "(" + dsRental.Tables[1].Rows[0]["Individual"].ToString() + ")";
        //lblBanglowCount.Text = "(" + dsRental.Tables[1].Rows[0]["Banglow"].ToString() + ")";

        lblAllCommercialCount.Text = "(" + dsRental.Tables[1].Rows[0]["AllCommercial"].ToString() + ")";
        lblIndustrialCount.Text = "(" + dsRental.Tables[1].Rows[0]["Indrustial"].ToString() + ")";
        lblOfficeSpaceCount.Text = "(" + dsRental.Tables[1].Rows[0]["Office"].ToString() + ")";
        lblRetailPropertyCount.Text = "(" + dsRental.Tables[1].Rows[0]["Retail"].ToString() + ")";

        lbl1BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["OneBR"].ToString() + ")";
        lbl2BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["TwoBR"].ToString() + ")";
        lbl3BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["ThreeBR"].ToString() + ")";
        lbl4BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["FourBR"].ToString() + ")";

        lbl1BACount.Text = "(" + dsRental.Tables[1].Rows[0]["OneBA"].ToString() + ")";
        lbl2BACount.Text = "(" + dsRental.Tables[1].Rows[0]["TwoBA"].ToString() + ")";
        lbl3BACount.Text = "(" + dsRental.Tables[1].Rows[0]["ThreeBA"].ToString() + ")";
        lbl4BACount.Text = "(" + dsRental.Tables[1].Rows[0]["FourBA"].ToString() + ")";

        lblNoneCount.Text = "(" + dsRental.Tables[1].Rows[0]["NoPets"].ToString() + ")";
        lblCatsCount.Text = "(" + dsRental.Tables[1].Rows[0]["Cats"].ToString() + ")";
        lblDogsCount.Text = "(" + dsRental.Tables[1].Rows[0]["Dogs"].ToString() + ")";
        lblcatsDogsCount.Text = "(" + dsRental.Tables[1].Rows[0]["CatsAndDog"].ToString() + ")";

        lbl1CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["OneCar"].ToString() + ")";
        lbl2CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["TwoCar"].ToString() + ")";
        lbl3CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["ThreeCar"].ToString() + ")";
        lbl4CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["FourCar"].ToString() + ")";
        lblCarNotAvailCount.Text = "(" + dsRental.Tables[1].Rows[0]["NoCar"].ToString() + ")";

        lblPartTimeCount.Text = "(" + dsRental.Tables[1].Rows[0]["PartTime"].ToString() + ")";
        lblFullTimeCount.Text = "(" + dsRental.Tables[1].Rows[0]["FullTime"].ToString() + ")";
        lblNotAvailCount.Text = "(" + dsRental.Tables[1].Rows[0]["WatchmanNotAvailable"].ToString() + ")";

        lblPhotosCount.Text = "(" + dsRental.Tables[1].Rows[0]["WithPhotos"].ToString() + ")";
        lblVideosCount.Text = "(" + dsRental.Tables[1].Rows[0]["WithVideos"].ToString() + ")";
        lblPhotosvideoCount.Text = "(" + dsRental.Tables[1].Rows[0]["WithBothPhotosAndVideos"].ToString() + ")";

    }

    private void setAllCounts(DataSet dsRental)
    {
        lblPostedByMeCount.Text = "(" + dsRental.Tables[1].Rows[0]["PostedByMe"].ToString() + ")";
        lblPostedByFriendsCount.Text = "(" + dsRental.Tables[1].Rows[0]["PostedByFriends"].ToString() + ")";
        lblPostedByAllCount.Text = "(" + dsRental.Tables[1].Rows[0]["PostedByAll"].ToString() + ")";

        lblAllCount.Text = "(" + dsRental.Tables[1].Rows[0]["SubCategoreyAll"].ToString() + ")";
        lblCommercialCount.Text = "(" + dsRental.Tables[1].Rows[0]["Commercial"].ToString() + ")";
        lblApartmentCount.Text = "(" + dsRental.Tables[1].Rows[0]["Apartment"].ToString() + ")";
        lblIndividualCount.Text = "(" + dsRental.Tables[1].Rows[0]["Individual"].ToString() + ")";
        lblBanglowCount.Text = "(" + dsRental.Tables[1].Rows[0]["Banglow"].ToString() + ")";

        lblAllCommercialCount.Text = "(" + dsRental.Tables[1].Rows[0]["AllCommercial"].ToString() + ")";
        lblIndustrialCount.Text = "(" + dsRental.Tables[1].Rows[0]["Indrustial"].ToString() + ")";
        lblOfficeSpaceCount.Text = "(" + dsRental.Tables[1].Rows[0]["Office"].ToString() + ")";
        lblRetailPropertyCount.Text = "(" + dsRental.Tables[1].Rows[0]["Retail"].ToString() + ")";

        lbl1BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["OneBR"].ToString() + ")";
        lbl2BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["TwoBR"].ToString() + ")";
        lbl3BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["ThreeBR"].ToString() + ")";
        lbl4BRCount.Text = "(" + dsRental.Tables[1].Rows[0]["FourBR"].ToString() + ")";

        lbl1BACount.Text = "(" + dsRental.Tables[1].Rows[0]["OneBA"].ToString() + ")";
        lbl2BACount.Text = "(" + dsRental.Tables[1].Rows[0]["TwoBA"].ToString() + ")";
        lbl3BACount.Text = "(" + dsRental.Tables[1].Rows[0]["ThreeBA"].ToString() + ")";
        lbl4BACount.Text = "(" + dsRental.Tables[1].Rows[0]["FourBA"].ToString() + ")";

        lblNoneCount.Text = "(" + dsRental.Tables[1].Rows[0]["NoPets"].ToString() + ")";
        lblCatsCount.Text = "(" + dsRental.Tables[1].Rows[0]["Cats"].ToString() + ")";
        lblDogsCount.Text = "(" + dsRental.Tables[1].Rows[0]["Dogs"].ToString() + ")";
        lblcatsDogsCount.Text = "(" + dsRental.Tables[1].Rows[0]["CatsAndDog"].ToString() + ")";

        lbl1CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["OneCar"].ToString() + ")";
        lbl2CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["TwoCar"].ToString() + ")";
        lbl3CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["ThreeCar"].ToString() + ")";
        lbl4CarCount.Text = "(" + dsRental.Tables[1].Rows[0]["FourCar"].ToString() + ")";
        lblCarNotAvailCount.Text = "(" + dsRental.Tables[1].Rows[0]["NoCar"].ToString() + ")";

        lblPartTimeCount.Text = "(" + dsRental.Tables[1].Rows[0]["PartTime"].ToString() + ")";
        lblFullTimeCount.Text = "(" + dsRental.Tables[1].Rows[0]["FullTime"].ToString() + ")";
        lblNotAvailCount.Text = "(" + dsRental.Tables[1].Rows[0]["WatchmanNotAvailable"].ToString() + ")";

        lblPhotosCount.Text = "(" + dsRental.Tables[1].Rows[0]["WithPhotos"].ToString() + ")";
        lblVideosCount.Text = "(" + dsRental.Tables[1].Rows[0]["WithVideos"].ToString() + ")";
        lblPhotosvideoCount.Text = "(" + dsRental.Tables[1].Rows[0]["WithBothPhotosAndVideos"].ToString() + ")";

    }

    private void mainSearchChanged()
    {
        getHiddenVariables();
        if (postedBy != "0")
        {
            setHiddenVariablesWithOutPosted();
        }
        else
        {
            setHiddenVariables();
        }

        //PostedByUndo();
        PriceUndo();
        BRUndo();
        BAUndo();
        PetsUndo();
        SqftsUndo();
        CarUndo();
        WatchmanUndo();
        ParametersUndo();

        txtLow.Text = "";
        txtHigh.Text = "";

        secSubCatPanel.Visible = false;

        txtMin.Text = "";
        txtMax.Text = "";

        loadAllListingInformation();

    }

    #region allClickEvents

    private void postedByMe()
    {
        Session["Facebook"] = "Can Edit";
        oAuthFacebook oAuth = new oAuthFacebook();
        if (Request["code"] != null)
        {
            string url = "http://apps.facebook.com/buddyagent/default.aspx?Posted=ME";
            oAuth.GetAccessToken(Request["code"], url);
            Api api = new Api(oAuth.Token);
            User u = api.GetUser();

            if (imgPostedbyMeTick.Visible == false)
            {
                linkPostedByUndo.Visible = true;

                imgPostedbyMeTick.Visible = true;
                lblPostedbyMe.Visible = true;
                lblPostedByMeCount.Visible = true;

                imgPostedbyFriendsTick.Visible = false;
                lblPostedbyFriends.Visible = false;
                lblPostedByFriendsCount.Visible = false;

                imgPostedbyAllTick.Visible = false;
                lblPostedbyAll.Visible = false;
                lblPostedByAllCount.Visible = false;

                Session["postedBy"] = "Me";
                Session["facebookId"] = u.id;
                loadAllListingInformation();
            }
            else if (imgPostedbyMeTick.Visible == true)
            {
                PostedByUndo();
            }
        }
    }

    private void postedByMyFriends()
    {
        oAuthFacebook oAuth = new oAuthFacebook();
        if (Request["code"] != null)
        {
            string url = "http://apps.facebook.com/buddyagent/default.aspx?Posted=MYFriends";
            oAuth.GetAccessToken(Request["code"], url);
            Api api = new Api(oAuth.Token);
            User u = api.GetUser();

            if (imgPostedbyFriendsTick.Visible == false)
            {
                linkPostedByUndo.Visible = true;

                imgPostedbyMeTick.Visible = false;
                lblPostedbyMe.Visible = false;
                lblPostedByMeCount.Visible = false;

                imgPostedbyFriendsTick.Visible = true;
                lblPostedbyFriends.Visible = true;
                lblPostedByFriendsCount.Visible = true;

                imgPostedbyAllTick.Visible = false;
                lblPostedbyAll.Visible = false;
                lblPostedByAllCount.Visible = false;

                Session["postedBy"] = "My Friends";
                Session["facebookId"] = u.id;
                loadAllListingInformation();
            }
            else if (imgPostedbyFriendsTick.Visible == true)
            {
                PostedByUndo();
            }
        }
    }

    protected void lblPostedbyMe_Click(object sender, EventArgs e)
    {
        oAuthFacebook oAuth = new oAuthFacebook();
        string url = "http://apps.facebook.com/buddyagent/default.aspx?Posted=ME";
        Response.Redirect(oAuth.AuthorizationLinkGet(url));
        //imgPostedbyMeTick.Visible = true;
        //imgPostedbyAllTick.Visible = false;
        //imgPostedbyFriendsTick.Visible = false;
        //Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=202706659773465&redirect_uri=http://apps.facebook.com/buddyagent/Default.aspx?Posted=ME");
        //postedByMe();
    }

    protected void lblPostedbyFriends_Click(object sender, EventArgs e)
    {
        oAuthFacebook oAuth = new oAuthFacebook();
        string url = "http://apps.facebook.com/buddyagent/default.aspx?Posted=MYFriends";
        Response.Redirect(oAuth.AuthorizationLinkGet(url));
        //Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=202706659773465&redirect_uri=http://apps.facebook.com/buddyagent/Default.aspx?Posted=MYFriend");
        //imgPostedbyMeTick.Visible = false;
        //imgPostedbyAllTick.Visible = false;
        //imgPostedbyFriendsTick.Visible = true;

        //Session["postedBy"] = "My Friends";
        //Session["facebookId"] = "100002385113963";

        //loadAllListingInformation();

    }

    protected void lblPostedbyAll_Click(object sender, EventArgs e)
    {
        //imgPostedbyMeTick.Visible = false;
        //imgPostedbyAllTick.Visible = true;
        //imgPostedbyFriendsTick.Visible = false;

        //Session["postedBy"] = "0";
        //Session["facebookId"] = "0";
        //loadAllListingInformation();
        PostedByUndo();
    }

    protected void lblCommercial_Click(object sender, EventArgs e)
    {
        mainSearchChanged();
        secSubCatPanel.Visible = true;
        imgBanglowTick.Visible = false;
        imgAllTick.Visible = false;
        imgIndividualTick.Visible = false;
        imgApartmentTick.Visible = false;
        imgCommercialTick.Visible = true;
        lblSelectedSubCategorey.Text = "Commercial";
        lblSelectedSubCategorey.Visible = true;

        Session["subcategorey"] = "Commercial";
        loadAllListingInformation();
    }

    protected void lblApartment_Click(object sender, EventArgs e)
    {
        mainSearchChanged();
        secSubCatPanel.Visible = false;
        imgBanglowTick.Visible = false;
        imgAllTick.Visible = false;
        imgCommercialTick.Visible = false;
        imgIndividualTick.Visible = false;
        imgApartmentTick.Visible = true;
        lblSelectedSubCategorey.Text = "Apartment";
        lblSelectedSubCategorey.Visible = true;

        Session["subcategorey"] = "Apartment";
        loadAllListingInformation();
    }

    protected void lblIndividual_Click(object sender, EventArgs e)
    {
        mainSearchChanged();
        secSubCatPanel.Visible = false;
        imgBanglowTick.Visible = false;
        imgAllTick.Visible = false;
        imgCommercialTick.Visible = false;
        imgApartmentTick.Visible = false;
        imgIndividualTick.Visible = true;
        lblSelectedSubCategorey.Text = "Individual House";
        lblSelectedSubCategorey.Visible = true;

        Session["subcategorey"] = "Individual House";
        loadAllListingInformation();
    }

    protected void linkBanglow_Click(object sender, EventArgs e)
    {
        mainSearchChanged();
        secSubCatPanel.Visible = false;
        imgBanglowTick.Visible = true;
        imgAllTick.Visible = false;
        imgCommercialTick.Visible = false;
        imgApartmentTick.Visible = false;
        imgIndividualTick.Visible = false;
        lblSelectedSubCategorey.Text = "Banglow";
        lblSelectedSubCategorey.Visible = true;

        Session["subcategorey"] = "Banglow";
        loadAllListingInformation();
    }

    protected void linkAll_Click(object sender, EventArgs e)
    {
        mainSearchChanged();
        secSubCatPanel.Visible = false;
        imgBanglowTick.Visible = false;
        imgAllTick.Visible = true;
        imgCommercialTick.Visible = false;
        imgApartmentTick.Visible = false;
        imgIndividualTick.Visible = false;
        lblSelectedSubCategorey.Text = "All";
        lblSelectedSubCategorey.Visible = false;

        Session["subcategorey"] = "0";
        loadAllListingInformation();
    }

    protected void linkAllCommercial_Click(object sender, EventArgs e)
    {
        if (imgAllCommercialTick.Visible == false)
        {
            linkSecSubCatUndo.Visible = false;

            imgAllCommercialTick.Visible = true;
            linkAllCommercial.Visible = true;
            lblAllCommercialCount.Visible = true;

            imgIndustrialTick.Visible = false;
            linkIndustrial.Visible = true;
            lblIndustrialCount.Visible = true;

            imgOfficeTick.Visible = false;
            linkOffice.Visible = true;
            lblOfficeSpaceCount.Visible = true;

            imgRetailTick.Visible = false;
            linkRetail.Visible = true;
            lblRetailPropertyCount.Visible = true;

            Session["secSubCat"] = "0";
            loadAllListingInformation();
        }
        else if (imgAllCommercialTick.Visible == true)
        {
            SecSubCatUndo();
        }

        imgAllCommercialTick.Visible = true;
        imgIndustrialTick.Visible = false;
        imgOfficeTick.Visible = false;
        imgRetailTick.Visible = false;

        Session["secSubCat"] = "0";
        loadAllListingInformation();
    }

    protected void linkIndustrial_Click(object sender, EventArgs e)
    {
        if (imgIndustrialTick.Visible == false)
        {
            linkSecSubCatUndo.Visible = true;

            imgAllCommercialTick.Visible = false;
            linkAllCommercial.Visible = false;
            lblAllCommercialCount.Visible = false;

            imgIndustrialTick.Visible = true;
            linkIndustrial.Visible = true;
            lblIndustrialCount.Visible = true;

            imgOfficeTick.Visible = false;
            linkOffice.Visible = false;
            lblOfficeSpaceCount.Visible = false;

            imgRetailTick.Visible = false;
            linkRetail.Visible = false;
            lblRetailPropertyCount.Visible = false;

            Session["secSubCat"] = "Indrustial property";
            loadAllListingInformation();
        }
        else if (imgIndustrialTick.Visible == true)
        {
            SecSubCatUndo();
        }
    }

    protected void linkOffice_Click(object sender, EventArgs e)
    {
        if (imgOfficeTick.Visible == false)
        {
            linkSecSubCatUndo.Visible = true;

            imgAllCommercialTick.Visible = false;
            linkAllCommercial.Visible = false;
            lblAllCommercialCount.Visible = false;

            imgIndustrialTick.Visible = false;
            linkIndustrial.Visible = false;
            lblIndustrialCount.Visible = false;

            imgOfficeTick.Visible = true;
            linkOffice.Visible = true;
            lblOfficeSpaceCount.Visible = true;

            imgRetailTick.Visible = false;
            linkRetail.Visible = false;
            lblRetailPropertyCount.Visible = false;

            Session["secSubCat"] = "Office Space";
            loadAllListingInformation();
        }
        else if (imgOfficeTick.Visible == true)
        {
            SecSubCatUndo();
        }
    }

    protected void linkRetail_Click(object sender, EventArgs e)
    {
        if (imgRetailTick.Visible == false)
        {
            linkSecSubCatUndo.Visible = true;

            imgAllCommercialTick.Visible = false;
            linkAllCommercial.Visible = false;
            lblAllCommercialCount.Visible = false;

            imgIndustrialTick.Visible = false;
            linkIndustrial.Visible = false;
            lblIndustrialCount.Visible = false;

            imgOfficeTick.Visible = false;
            linkOffice.Visible = false;
            lblOfficeSpaceCount.Visible = false;

            imgRetailTick.Visible = true;
            linkRetail.Visible = true;
            lblRetailPropertyCount.Visible = true;

            Session["secSubCat"] = "Retail Property";
            loadAllListingInformation();
        }
        else if (imgRetailTick.Visible == true)
        {
            SecSubCatUndo();
        }
    }

    protected void btnsearch_Click(object sender, EventArgs e)
    {
        linkPriceUndo.Visible = true;

        Session["minPrice"] = txtLow.Text;
        Session["maxPrice"] = txtHigh.Text;

        loadAllListingInformation();

    }

    protected void lbl1BR_Click(object sender, EventArgs e)
    {
        if (img1BRTick.Visible == false)
        {
            linkBRUndo.Visible = true;

            img1BRTick.Visible = true;
            lbl1BR.Visible = true;
            lbl1BRCount.Visible = true;

            img2BRTick.Visible = false;
            lbl2BR.Visible = false;
            lbl2BRCount.Visible = false;

            img3BRTick.Visible = false;
            lbl3BR.Visible = false;
            lbl3BRCount.Visible = false;

            img4BRTick.Visible = false;
            lbl4BR.Visible = false;
            lbl4BRCount.Visible = false;

            Session["BR"] = "1";
            loadAllListingInformation();
        }
        else if (img1BRTick.Visible == true)
        {
            BRUndo();
        }

    }

    protected void lbl2BR_Click(object sender, EventArgs e)
    {
        if (img2BRTick.Visible == false)
        {
            linkBRUndo.Visible = true;

            img1BRTick.Visible = false;
            lbl1BR.Visible = false;
            lbl1BRCount.Visible = false;

            img2BRTick.Visible = true;
            lbl2BR.Visible = true;
            lbl2BRCount.Visible = true;

            img3BRTick.Visible = false;
            lbl3BR.Visible = false;
            lbl3BRCount.Visible = false;

            img4BRTick.Visible = false;
            lbl4BR.Visible = false;
            lbl4BRCount.Visible = false;

            Session["BR"] = "2";
            loadAllListingInformation();
        }
        else if (img2BRTick.Visible == true)
        {
            BRUndo();
        }

    }

    protected void lbl3BR_Click(object sender, EventArgs e)
    {
        if (img3BRTick.Visible == false)
        {
            linkBRUndo.Visible = true;

            img1BRTick.Visible = false;
            lbl1BR.Visible = false;
            lbl1BRCount.Visible = false;

            img2BRTick.Visible = false;
            lbl2BR.Visible = false;
            lbl2BRCount.Visible = false;

            img3BRTick.Visible = true;
            lbl3BR.Visible = true;
            lbl3BRCount.Visible = true;

            img4BRTick.Visible = false;
            lbl4BR.Visible = false;
            lbl4BRCount.Visible = false;

            Session["BR"] = "3";
            loadAllListingInformation();
        }
        else if (img3BRTick.Visible == true)
        {
            BRUndo();
        }

    }

    protected void lbl4BR_Click(object sender, EventArgs e)
    {
        if (img4BRTick.Visible == false)
        {
            linkBRUndo.Visible = true;

            img1BRTick.Visible = false;
            lbl1BR.Visible = false;
            lbl1BRCount.Visible = false;

            img2BRTick.Visible = false;
            lbl2BR.Visible = false;
            lbl2BRCount.Visible = false;

            img3BRTick.Visible = false;
            lbl3BR.Visible = false;
            lbl3BRCount.Visible = false;

            img4BRTick.Visible = true;
            lbl4BR.Visible = true;
            lbl4BRCount.Visible = true;

            Session["BR"] = "4";
            loadAllListingInformation();
        }
        else if (img4BRTick.Visible == true)
        {
            BRUndo();
        }

    }

    protected void lbl1BA_Click(object sender, EventArgs e)
    {
        if (img1BATick.Visible == false)
        {
            linkBAUndo.Visible = true;

            img1BATick.Visible = true;
            lbl1BA.Visible = true;
            lbl1BACount.Visible = true;

            img2BATick.Visible = false;
            lbl2BA.Visible = false;
            lbl2BACount.Visible = false;

            img3BATick.Visible = false;
            lbl3BA.Visible = false;
            lbl3BACount.Visible = false;

            img4BATick.Visible = false;
            lbl4BA.Visible = false;
            lbl4BACount.Visible = false;

            Session["BA"] = "1";
            loadAllListingInformation();
        }
        else if (img1BATick.Visible == true)
        {
            BAUndo();
        }
    }

    protected void lbl2BA_Click(object sender, EventArgs e)
    {
        if (img2BATick.Visible == false)
        {
            linkBAUndo.Visible = true;

            img1BATick.Visible = false;
            lbl1BA.Visible = false;
            lbl1BACount.Visible = false;

            img2BATick.Visible = true;
            lbl2BA.Visible = true;
            lbl2BACount.Visible = true;

            img3BATick.Visible = false;
            lbl3BA.Visible = false;
            lbl3BACount.Visible = false;

            img4BATick.Visible = false;
            lbl4BA.Visible = false;
            lbl4BACount.Visible = false;

            Session["BA"] = "2";
            loadAllListingInformation();
        }
        else if (img2BATick.Visible == true)
        {
            BAUndo();
        }


    }

    protected void lbl3BA_Click(object sender, EventArgs e)
    {
        if (img3BATick.Visible == false)
        {
            linkBAUndo.Visible = true;

            img1BATick.Visible = false;
            lbl1BA.Visible = false;
            lbl1BACount.Visible = false;

            img2BATick.Visible = false;
            lbl2BA.Visible = false;
            lbl2BACount.Visible = false;

            img3BATick.Visible = true;
            lbl3BA.Visible = true;
            lbl3BACount.Visible = true;

            img4BATick.Visible = false;
            lbl4BA.Visible = false;
            lbl4BACount.Visible = false;

            Session["BA"] = "3";
            loadAllListingInformation();
        }
        else if (img3BATick.Visible == true)
        {
            BAUndo();
        }
    }

    protected void lbl4BA_Click(object sender, EventArgs e)
    {
        if (img4BATick.Visible == false)
        {
            linkBAUndo.Visible = true;

            img1BATick.Visible = false;
            lbl1BA.Visible = false;
            lbl1BACount.Visible = false;

            img2BATick.Visible = false;
            lbl2BA.Visible = false;
            lbl2BACount.Visible = false;

            img3BATick.Visible = false;
            lbl3BA.Visible = false;
            lbl3BACount.Visible = false;

            img4BATick.Visible = true;
            lbl4BA.Visible = true;
            lbl4BACount.Visible = true;

            Session["BA"] = "4";
            loadAllListingInformation();
        }
        else if (img4BATick.Visible == true)
        {
            BAUndo();
        }
    }

    protected void lblCats_Click(object sender, EventArgs e)
    {
        if (imgCatsTick.Visible == false)
        {
            linkPetsUndo.Visible = true;

            imgCatsTick.Visible = true;
            lblCats.Visible = true;
            lblCatsCount.Visible = true;

            imgDogsTick.Visible = false;
            lblDogs.Visible = false;
            lblDogsCount.Visible = false;

            imgCatsDogsTick.Visible = false;
            linkcatsDogs.Visible = false;
            lblcatsDogsCount.Visible = false;

            imgNoneTick.Visible = false;
            lblNone.Visible = false;
            lblNoneCount.Visible = false;

            Session["Pets"] = "Cats Ok";
            loadAllListingInformation();
        }
        else if (imgCatsTick.Visible == true)
        {
            PetsUndo();
        }
    }

    protected void lblDogs_Click(object sender, EventArgs e)
    {
        if (imgDogsTick.Visible == false)
        {
            linkPetsUndo.Visible = true;

            imgCatsTick.Visible = false;
            lblCats.Visible = false;
            lblCatsCount.Visible = false;

            imgDogsTick.Visible = true;
            lblDogs.Visible = true;
            lblDogsCount.Visible = true;

            imgCatsDogsTick.Visible = false;
            linkcatsDogs.Visible = false;
            lblcatsDogsCount.Visible = false;

            imgNoneTick.Visible = false;
            lblNone.Visible = false;
            lblNoneCount.Visible = false;

            Session["Pets"] = "Dogs Ok";
            loadAllListingInformation();
        }
        else if (imgDogsTick.Visible == true)
        {
            PetsUndo();
        }
    }

    protected void linkcatsDogs_Click(object sender, EventArgs e)
    {
        if (imgCatsDogsTick.Visible == false)
        {
            linkPetsUndo.Visible = true;

            imgCatsTick.Visible = false;
            lblCats.Visible = false;
            lblCatsCount.Visible = false;

            imgDogsTick.Visible = false;
            lblDogs.Visible = false;
            lblDogsCount.Visible = false;

            imgCatsDogsTick.Visible = true;
            linkcatsDogs.Visible = true;
            lblcatsDogsCount.Visible = true;

            imgNoneTick.Visible = false;
            lblNone.Visible = false;
            lblNoneCount.Visible = false;

            Session["Pets"] = "Cats Ok/Dogs Ok";
            loadAllListingInformation();
        }
        else if (imgCatsDogsTick.Visible == true)
        {
            PetsUndo();
        }

    }

    protected void lblNoPets_Click(object sender, EventArgs e)
    {
        if (imgNoneTick.Visible == false)
        {
            linkPetsUndo.Visible = true;

            imgCatsTick.Visible = false;
            lblCats.Visible = false;
            lblCatsCount.Visible = false;

            imgDogsTick.Visible = false;
            lblDogs.Visible = false;
            lblDogsCount.Visible = false;

            imgCatsDogsTick.Visible = false;
            linkcatsDogs.Visible = false;
            lblcatsDogsCount.Visible = false;

            imgNoneTick.Visible = true;
            lblNone.Visible = true;
            lblNoneCount.Visible = true;

            Session["Pets"] = "No Pets";
            loadAllListingInformation();
        }
        else if (imgNoneTick.Visible == true)
        {
            PetsUndo();
        }

    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        linkSqftsUndo.Visible = true;

        Session["minSqfts"] = txtMin.Text;
        Session["maxSqfts"] = txtMax.Text;

        loadAllListingInformation();

    }

    protected void link1Car_Click(object sender, EventArgs e)
    {
        if (img1CarTick.Visible == false)
        {
            linkCarUndo.Visible = true;

            img1CarTick.Visible = true;
            link1Car.Visible = true;
            lbl1CarCount.Visible = true;

            img2CarTick.Visible = false;
            link2Cars.Visible = false;
            lbl2CarCount.Visible = false;

            img3CarTick.Visible = false;
            link3Car.Visible = false;
            lbl3CarCount.Visible = false;

            img4CarTick.Visible = false;
            link4car.Visible = false;
            lbl4CarCount.Visible = false;

            imgCarNotAvailTick.Visible = false;
            linkCarNotAvail.Visible = false;
            lblCarNotAvailCount.Visible = false;

            Session["CarParking"] = "1";
            loadAllListingInformation();

        }
        else if (img1CarTick.Visible == true)
        {
            CarUndo();
        }

        img2CarTick.Visible = false;
        img3CarTick.Visible = false;
        img4CarTick.Visible = false;
        imgCarNotAvailTick.Visible = false;

        Session["CarParking"] = "1";

        loadAllListingInformation();
    }

    protected void link2Cars_Click(object sender, EventArgs e)
    {
        if (img2CarTick.Visible == false)
        {
            linkCarUndo.Visible = true;

            img1CarTick.Visible = false;
            link1Car.Visible = false;
            lbl1CarCount.Visible = false;

            img2CarTick.Visible = true;
            link2Cars.Visible = true;
            lbl2CarCount.Visible = true;

            img3CarTick.Visible = false;
            link3Car.Visible = false;
            lbl3CarCount.Visible = false;

            img4CarTick.Visible = false;
            link4car.Visible = false;
            lbl4CarCount.Visible = false;

            imgCarNotAvailTick.Visible = false;
            linkCarNotAvail.Visible = false;
            lblCarNotAvailCount.Visible = false;

            Session["CarParking"] = "2";
            loadAllListingInformation();

        }
        else if (img2CarTick.Visible == true)
        {
            CarUndo();
        }



    }

    protected void link3Car_Click(object sender, EventArgs e)
    {
        if (img3CarTick.Visible == false)
        {
            linkCarUndo.Visible = true;

            img1CarTick.Visible = false;
            link1Car.Visible = false;
            lbl1CarCount.Visible = false;

            img2CarTick.Visible = false;
            link2Cars.Visible = false;
            lbl2CarCount.Visible = false;

            img3CarTick.Visible = true;
            link3Car.Visible = true;
            lbl3CarCount.Visible = true;

            img4CarTick.Visible = false;
            link4car.Visible = false;
            lbl4CarCount.Visible = false;

            imgCarNotAvailTick.Visible = false;
            linkCarNotAvail.Visible = false;
            lblCarNotAvailCount.Visible = false;

            Session["CarParking"] = "3";
            loadAllListingInformation();

        }
        else if (img3CarTick.Visible == true)
        {
            CarUndo();
        }

    }

    protected void link4car_Click(object sender, EventArgs e)
    {
        if (img4CarTick.Visible == false)
        {
            linkCarUndo.Visible = true;

            img1CarTick.Visible = false;
            link1Car.Visible = false;
            lbl1CarCount.Visible = false;

            img2CarTick.Visible = false;
            link2Cars.Visible = false;
            lbl2CarCount.Visible = false;

            img3CarTick.Visible = false;
            link3Car.Visible = false;
            lbl3CarCount.Visible = false;

            img4CarTick.Visible = true;
            link4car.Visible = true;
            lbl4CarCount.Visible = true;

            imgCarNotAvailTick.Visible = false;
            linkCarNotAvail.Visible = false;
            lblCarNotAvailCount.Visible = false;

            Session["CarParking"] = "4";
            loadAllListingInformation();

        }
        else if (img4CarTick.Visible == true)
        {
            CarUndo();
        }
    }

    protected void linkCarNotAvail_Click(object sender, EventArgs e)
    {
        if (imgCarNotAvailTick.Visible == false)
        {
            linkCarUndo.Visible = true;

            img1CarTick.Visible = false;
            link1Car.Visible = false;
            lbl1CarCount.Visible = false;

            img2CarTick.Visible = false;
            link2Cars.Visible = false;
            lbl2CarCount.Visible = false;

            img3CarTick.Visible = false;
            link3Car.Visible = false;
            lbl3CarCount.Visible = false;

            img4CarTick.Visible = false;
            link4car.Visible = false;
            lbl4CarCount.Visible = false;

            imgCarNotAvailTick.Visible = true;
            linkCarNotAvail.Visible = true;
            lblCarNotAvailCount.Visible = true;

            Session["CarParking"] = "0";
            loadAllListingInformation();

        }
        else if (imgCarNotAvailTick.Visible == true)
        {
            CarUndo();
        }

    }

    protected void linkPartTime_Click(object sender, EventArgs e)
    {
        if (imgPartTimeTick.Visible == false)
        {
            linkWatchmanUndo.Visible = true;

            imgPartTimeTick.Visible = true;
            linkPartTime.Visible = true;
            lblPartTimeCount.Visible = true;

            imgFullTimeTick.Visible = false;
            linkFullTime.Visible = false;
            lblFullTimeCount.Visible = false;

            imgNotAvailTick.Visible = false;
            linkNotAvail.Visible = false;
            lblNotAvailCount.Visible = false;

            Session["watchman"] = "Part-Time";
            loadAllListingInformation();
        }
        else if (imgPartTimeTick.Visible == true)
        {
            WatchmanUndo();
        }
    }

    protected void linkFullTime_Click(object sender, EventArgs e)
    {
        if (imgFullTimeTick.Visible == false)
        {
            linkWatchmanUndo.Visible = true;

            imgPartTimeTick.Visible = false;
            linkPartTime.Visible = false;
            lblPartTimeCount.Visible = false;

            imgFullTimeTick.Visible = true;
            linkFullTime.Visible = true;
            lblFullTimeCount.Visible = true;

            imgNotAvailTick.Visible = false;
            linkNotAvail.Visible = false;
            lblNotAvailCount.Visible = false;

            Session["watchman"] = "Full-Time";
            loadAllListingInformation();
        }
        else if (imgFullTimeTick.Visible == true)
        {
            WatchmanUndo();
        }
    }

    protected void linkNotAvail_Click(object sender, EventArgs e)
    {
        if (imgNotAvailTick.Visible == false)
        {
            linkWatchmanUndo.Visible = true;

            imgPartTimeTick.Visible = false;
            linkPartTime.Visible = false;
            lblPartTimeCount.Visible = false;

            imgFullTimeTick.Visible = false;
            linkFullTime.Visible = false;
            lblFullTimeCount.Visible = false;

            imgNotAvailTick.Visible = true;
            linkNotAvail.Visible = true;
            lblNotAvailCount.Visible = true;

            Session["watchman"] = "Not Available";
            loadAllListingInformation();
        }
        else if (imgNotAvailTick.Visible == true)
        {
            WatchmanUndo();
        }
    }

    protected void lblPhoto_Click(object sender, EventArgs e)
    {
        if (imgPhotoTick.Visible == false)
        {
            linkParametersUndo.Visible = true;

            imgPhotoTick.Visible = true;
            lblPhoto.Visible = true;
            lblPhotosCount.Visible = true;

            imgVideosTick.Visible = false;
            lblVideos.Visible = false;
            lblVideosCount.Visible = false;

            imgPhotosVideosTick.Visible = false;
            lblPhotosVideos.Visible = false;
            lblPhotosvideoCount.Visible = false;

            Session["parameters"] = "With Photos";
            loadAllListingInformation();
        }
        else if (imgPhotoTick.Visible == true)
        {
            ParametersUndo();
        }

    }

    protected void lblVideos_Click(object sender, EventArgs e)
    {
        if (imgVideosTick.Visible == false)
        {
            linkParametersUndo.Visible = true;

            imgPhotoTick.Visible = false;
            lblPhoto.Visible = false;
            lblPhotosCount.Visible = false;

            imgVideosTick.Visible = true;
            lblVideos.Visible = true;
            lblVideosCount.Visible = true;

            imgPhotosVideosTick.Visible = false;
            lblPhotosVideos.Visible = false;
            lblPhotosvideoCount.Visible = false;

            Session["parameters"] = "Videos";
            loadAllListingInformation();
        }
        else if (imgVideosTick.Visible == true)
        {
            ParametersUndo();
        }

    }

    protected void lblPhotosVideos_Click(object sender, EventArgs e)
    {
        if (imgPhotosVideosTick.Visible == false)
        {
            linkParametersUndo.Visible = true;

            imgPhotoTick.Visible = false;
            lblPhoto.Visible = false;
            lblPhotosCount.Visible = false;

            imgVideosTick.Visible = false;
            lblVideos.Visible = false;
            lblVideosCount.Visible = false;

            imgPhotosVideosTick.Visible = true;
            lblPhotosVideos.Visible = true;
            lblPhotosvideoCount.Visible = true;

            Session["parameters"] = "bothPhotos&Videos";
            loadAllListingInformation();
        }
        else if (imgPhotosVideosTick.Visible == true)
        {
            ParametersUndo();
        }
    }

    #endregion

    protected void ddlsearch_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlsearch.SelectedItem.Text == "Price In Ascending")
            Session["AscOrder"] = 1;
        else if (ddlsearch.SelectedItem.Text == "Price In Descending")
            Session["AscOrder"] = 0;
        else
            Session["AscOrder"] = -1;

        loadAllListingInformation();
    }

    #region allUndoClick

    protected void linkPostedByUndo_Click(object sender, EventArgs e)
    {
        PostedByUndo();
    }

    protected void linkSecSubCatUndo_Click(object sender, EventArgs e)
    {
        SecSubCatUndo();
    }

    protected void linkPriceUndo_Click(object sender, EventArgs e)
    {
        PriceUndo();
    }

    protected void linkBRUndo_Click(object sender, EventArgs e)
    {
        BRUndo();
    }

    protected void linkBAUndo_Click(object sender, EventArgs e)
    {
        BAUndo();
    }

    protected void linkPetsUndo_Click(object sender, EventArgs e)
    {
        PetsUndo();
    }

    protected void linkSqftsUndo_Click(object sender, EventArgs e)
    {
        SqftsUndo();
    }

    protected void linkCarUndo_Click(object sender, EventArgs e)
    {
        CarUndo();
    }

    protected void linkWatchmanUndo_Click(object sender, EventArgs e)
    {
        WatchmanUndo();
    }

    protected void linkParametersUndo_Click(object sender, EventArgs e)
    {
        ParametersUndo();
    }

    private void PostedByUndo()
    {
        linkPostedByUndo.Visible = false;

        imgPostedbyMeTick.Visible = false;
        lblPostedbyMe.Visible = true;
        lblPostedByMeCount.Visible = false;

        imgPostedbyFriendsTick.Visible = false;
        lblPostedbyFriends.Visible = true;
        lblPostedByFriendsCount.Visible = false;

        imgPostedbyAllTick.Visible = true;
        lblPostedbyAll.Visible = true;
        lblPostedByAllCount.Visible = true;

        Session["postedBy"] = "0";
        Session["facebookId"] = "0";
        loadAllListingInformation();
        post = true;
    }

    protected void SecSubCatUndo()
    {
        linkSecSubCatUndo.Visible = false;

        imgAllCommercialTick.Visible = true;
        linkAllCommercial.Visible = true;
        lblAllCommercialCount.Visible = true;

        imgIndustrialTick.Visible = false;
        linkIndustrial.Visible = true;
        lblIndustrialCount.Visible = true;

        imgOfficeTick.Visible = false;
        linkOffice.Visible = true;
        lblOfficeSpaceCount.Visible = true;

        imgRetailTick.Visible = false;
        linkRetail.Visible = true;
        lblRetailPropertyCount.Visible = true;

        Session["secSubCat"] = "0";
        loadAllListingInformation();
    }

    private void PriceUndo()
    {
        linkPriceUndo.Visible = false;

        txtLow.Text = "Low";
        txtHigh.Text = "High";

        Session["minPrice"] = -1;
        Session["maxPrice"] = -1;

        loadAllListingInformation();
    }

    private void BRUndo()
    {
        linkBRUndo.Visible = false;

        img1BRTick.Visible = false;
        lbl1BR.Visible = true;
        lbl1BRCount.Visible = true;

        img2BRTick.Visible = false;
        lbl2BR.Visible = true;
        lbl2BRCount.Visible = true;

        img3BRTick.Visible = false;
        lbl3BR.Visible = true;
        lbl3BRCount.Visible = true;

        img4BRTick.Visible = false;
        lbl4BR.Visible = true;
        lbl4BRCount.Visible = true;

        Session["BR"] = "-1";
        loadAllListingInformation();
    }

    private void BAUndo()
    {
        linkBAUndo.Visible = false;

        img1BATick.Visible = false;
        lbl1BA.Visible = true;
        lbl1BACount.Visible = true;

        img2BATick.Visible = false;
        lbl2BA.Visible = true;
        lbl2BACount.Visible = true;

        img3BATick.Visible = false;
        lbl3BA.Visible = true;
        lbl3BACount.Visible = true;

        img4BATick.Visible = false;
        lbl4BA.Visible = true;
        lbl4BACount.Visible = true;

        Session["BA"] = "-1";
        loadAllListingInformation();
    }

    private void PetsUndo()
    {
        linkPetsUndo.Visible = false;

        imgCatsTick.Visible = false;
        lblCats.Visible = true;
        lblCatsCount.Visible = true;

        imgDogsTick.Visible = false;
        lblDogs.Visible = true;
        lblDogsCount.Visible = true;

        imgCatsDogsTick.Visible = false;
        linkcatsDogs.Visible = true;
        lblcatsDogsCount.Visible = true;

        imgNoneTick.Visible = false;
        lblNone.Visible = true;
        lblNoneCount.Visible = true;

        Session["Pets"] = "0";
        loadAllListingInformation();

    }

    private void SqftsUndo()
    {
        linkSqftsUndo.Visible = false;

        txtMin.Text = "Low";
        txtMax.Text = "High";

        Session["minSqfts"] = -1;
        Session["maxSqfts"] = -1;

        loadAllListingInformation();
    }

    private void CarUndo()
    {
        linkCarUndo.Visible = false;

        img1CarTick.Visible = false;
        link1Car.Visible = true;
        lbl1CarCount.Visible = true;

        img2CarTick.Visible = false;
        link2Cars.Visible = true;
        lbl2CarCount.Visible = true;

        img3CarTick.Visible = false;
        link3Car.Visible = true;
        lbl3CarCount.Visible = true;

        img4CarTick.Visible = false;
        link4car.Visible = true;
        lbl4CarCount.Visible = true;

        imgCarNotAvailTick.Visible = false;
        linkCarNotAvail.Visible = true;
        lblCarNotAvailCount.Visible = true;

        Session["CarParking"] = "-1";
        loadAllListingInformation();

    }

    private void WatchmanUndo()
    {
        linkWatchmanUndo.Visible = false;

        imgPartTimeTick.Visible = false;
        linkPartTime.Visible = true;
        lblPartTimeCount.Visible = true;

        imgFullTimeTick.Visible = false;
        linkFullTime.Visible = true;
        lblFullTimeCount.Visible = true;

        imgNotAvailTick.Visible = false;
        linkNotAvail.Visible = true;
        lblNotAvailCount.Visible = true;

        Session["watchman"] = "0";
        loadAllListingInformation();
    }

    private void ParametersUndo()
    {
        linkParametersUndo.Visible = false;

        imgPhotoTick.Visible = false;
        lblPhoto.Visible = true;
        lblPhotosCount.Visible = true;

        imgVideosTick.Visible = false;
        lblVideos.Visible = true;
        lblVideosCount.Visible = true;

        imgPhotosVideosTick.Visible = false;
        lblPhotosVideos.Visible = true;
        lblPhotosvideoCount.Visible = true;

        Session["parameters"] = "0";
        loadAllListingInformation();
    }

    #endregion

    private void NoListingInfoAvailable()
    {
        NoListingAvailable.Visible = true;

        #region showAppliedConditions

        getHiddenVariables();
        hideAll();

        if (postedBy != "0")
        {
            imgPostedBy.Visible = true;
            lablePostedBy.Visible = true;
            lblPostedByDynamic.Text = postedBy;
            lblPostedByDynamic.Visible = true;
            linkPostedByRemove.Visible = true;
        }

        if (secSubCat != "0")
        {
            imgSecSubCat.Visible = true;
            lblSecSubCat.Visible = true;
            lblSecSubCatDynamic.Text = secSubCat;
            lblSecSubCatDynamic.Visible = true;
            linkSecSubCategoreyRemove.Visible = true;
        }

        if ((minPrice != -1) && (maxPrice != -1))
        {
            imgPrice.Visible = true;
            lablePrice.Visible = true;
            lblPriceDynamic.Text = "Between " + minPrice.ToString() + " and " + maxPrice.ToString();
            lblPriceDynamic.Visible = true;
            linkPriceRemove.Visible = true;
        }

        if (BR != -1)
        {
            imgBR.Visible = true;
            lblBR.Visible = true;
            lblBRDynamic.Text = BR.ToString();
            lblBRDynamic.Visible = true;
            linkBRRemove.Visible = true;
        }

        if (BA != -1)
        {
            imgBA.Visible = true;
            lblBA.Visible = true;
            lblBADynamic.Text = BA.ToString();
            lblBADynamic.Visible = true;
            linkBARemove.Visible = true;
        }

        if (Pets != "0")
        {
            imgPets.Visible = true;
            lablePets.Visible = true;
            lblPetsDynamic.Text = Pets;
            lblPetsDynamic.Visible = true;
            linkPetsRemove.Visible = true;
        }

        if ((minSqfts != -1) && (minSqfts != -1))
        {
            imgSqfts.Visible = true;
            lblSqfts.Visible = true;
            lblSqftsDynamic.Text = "Between " + minSqfts.ToString() + " and " + maxSqfts.ToString();
            lblSqftsDynamic.Visible = true;
            linkSqftsRemove.Visible = true;
        }

        if (CarParking != -1)
        {
            imgCar.Visible = true;
            labelCar.Visible = true;
            lblCarDynamic.Text = CarParking.ToString();
            lblCarDynamic.Visible = true;
            linkCarRemove.Visible = true;
        }

        if (watchman != "0")
        {
            imgWatchman.Visible = true;
            labelWatchman.Visible = true;
            lblWatchmanDynamic.Text = watchman;
            lblWatchmanDynamic.Visible = true;
            linkWatchmanRemove.Visible = true;
        }

        if (parameters != "0")
        {
            imgParameters.Visible = true;
            labelParameter.Visible = true;
            lblParametersDynamic.Text = parameters.ToString();
            lblParametersDynamic.Visible = true;
            linkparameterRemove.Visible = true;
        }
        #endregion
    }

    private void hideAll()
    {
        imgPostedBy.Visible = false;
        lablePostedBy.Visible = false;
        lblPostedByDynamic.Text = "";
        lblPostedByDynamic.Visible = false;
        linkPostedByRemove.Visible = false;

        imgSecSubCat.Visible = false;
        lblSecSubCat.Visible = false;
        lblSecSubCatDynamic.Text = "";
        lblSecSubCatDynamic.Visible = false;
        linkSecSubCategoreyRemove.Visible = false;

        imgPrice.Visible = false;
        lablePrice.Visible = false;
        lblPriceDynamic.Text = "";
        lblPriceDynamic.Visible = false;
        linkPriceRemove.Visible = false;

        imgBR.Visible = false;
        lblBR.Visible = false;
        lblBRDynamic.Text = "";
        lblBRDynamic.Visible = false;
        linkBRRemove.Visible = false;

        imgBA.Visible = false;
        lblBA.Visible = false;
        lblBADynamic.Text = "";
        lblBADynamic.Visible = false;
        linkBARemove.Visible = false;

        imgPets.Visible = false;
        lablePets.Visible = false;
        lblPetsDynamic.Text = Pets;
        lblPetsDynamic.Visible = false;
        linkPetsRemove.Visible = false;

        imgSqfts.Visible = false;
        lblSqfts.Visible = false;
        lblSqftsDynamic.Text = "";
        lblSqftsDynamic.Visible = false;
        linkSqftsRemove.Visible = false;

        imgCar.Visible = false;
        labelCar.Visible = false;
        lblCarDynamic.Text = "";
        lblCarDynamic.Visible = false;
        linkCarRemove.Visible = false;

        imgWatchman.Visible = false;
        labelWatchman.Visible = false;
        lblWatchmanDynamic.Text = "";
        lblWatchmanDynamic.Visible = false;
        linkWatchmanRemove.Visible = false;

        imgParameters.Visible = false;
        labelParameter.Visible = false;
        lblParametersDynamic.Text = "";
        lblParametersDynamic.Visible = false;
        linkparameterRemove.Visible = false;

    }

    #region allRemoveClick

    protected void linkPostedByRemove_Click(object sender, EventArgs e)
    {
        PostedByUndo();
        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkSecSubCategoreyRemove_Click(object sender, EventArgs e)
    {
        SecSubCatUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkPriceRemove_Click(object sender, EventArgs e)
    {
        PriceUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkBRRemove_Click(object sender, EventArgs e)
    {
        BRUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkBARemove_Click(object sender, EventArgs e)
    {
        BAUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkPetsRemove_Click(object sender, EventArgs e)
    {
        PetsUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkSqftsRemove_Click(object sender, EventArgs e)
    {
        SqftsUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkCarRemove_Click(object sender, EventArgs e)
    {
        CarUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkWatchmanRemove_Click(object sender, EventArgs e)
    {
        WatchmanUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    protected void linkparameterRemove_Click(object sender, EventArgs e)
    {
        ParametersUndo();

        if (flag == true)
            NoListingAvailable.Visible = false;
        else
            NoListingAvailable.Visible = true;
    }

    #endregion

    protected void gvControls_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvControls.PageIndex = e.NewPageIndex;
        getHiddenVariables();

        DataSet dsRental = new DataSet();
        dsRental = BuddyAgentDAL.searchPatternRental(postedBy, subcategorey, secSubCat, minPrice, maxPrice, BR, BA, CarParking, minSqfts, maxSqfts,
            watchman, parameters, Pets, ascOrder, clientId, facebookId, active);

        //ControlPlace.Controls.Clear();
        NoListingAvailable.Visible = false;
        if (dsRental.Tables[0].Rows.Count == 0)
        {
            gvControls.DataSource = null;
            gvControls.DataBind();
            NoListingInfoAvailable();
            flag = false;
        }
        else
        {
            flag = true;

            int firstValue, lastValue;

            firstValue = (gvControls.PageIndex) * (gvControls.PageSize) + 1;

            lastValue = (gvControls.PageIndex + 1) * (gvControls.PageSize);

            if (lastValue > dsRental.Tables[0].Rows.Count)
                lastValue = dsRental.Tables[0].Rows.Count;

            lblRentalCount.Text = "Rentals ( " + firstValue.ToString() + " - " + lastValue.ToString() + " of " + dsRental.Tables[0].Rows.Count.ToString() + " )";


            gvControls.DataSource = dsRental.Tables[0];
            gvControls.DataBind();
        }
        if (!IsPostBack)
            setAllCounts(dsRental);
        else
            setCounts(dsRental);
        if (post)
        {
            setAllCounts(dsRental);
            post = false;
        }

    }
}